<template>
	<view>
		<view class="title" style="text-align: center;">
			<span style="font-size: 24px;">京东登录</span>
		</view>
		<view>
			<form @submit="formSubmit">
				<view class="uni-form-item uni-column account">
					<input class="uni-input" name="account" placeholder="请输入账号" />
				</view>
				<view class="uni-form-item uni-column password">
					<input class="uni-input" name="password" type="password" placeholder="请输入密码" />
				</view>
				<view class="uni-btn-v uni-submit">
					<button form-type="submit">提交</button>
				</view>
			</form>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {

			}
		},
		methods: {
			formSubmit: function(e) {
				var formdata = e.detail.value
				uni.request({
						url: 'http://localhost:8081/api',
						data: {
							"account": formdata.account,
							"password": formdata.password
						},
						success: (res) => {
							if (res.data) {
								uni.setStorage({
									key: 'account',
									data: formdata.account
								});
								uni.switchTab({
									url: '/pages/index/index'
								});
							} else {
								uni.showToast({
									title: "账号或密码错误",
									duration: 2000
								});
							}
						}
					})
				}
			}
		}
</script>

<style>
	.account {
		margin-top: 30px;
		margin-left: 20px;
		margin-right: 20px;
		border-bottom: 1px solid black;
	}

	.password {
		margin-top: 30px;
		margin-left: 20px;
		margin-right: 20px;
		border-bottom: 1px solid black;
	}

	.uni-submit {
		margin-top: 30px;
		margin-left: 20px;
		margin-right: 20px;
	}
</style>